/*
  * Copyright (C) 2012 maxim
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
  * published by the Free Software Foundation; either version 2 of the
  * License, or (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful, but
  * WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  * USA
  */


#include "tests.h"

#include "user_threads.h"
#include "user_mutex.h"

#include <stdio.h>
#include <stdlib.h>
#include <assert.h>

/* Another mutex test
 * Test initialization junk.
 * You really have to use a hash table or list to pass that.... */

void test11() {

	msg("\nRunning test #11...");

	uthread_mutex_t mutex1 = NULL;
	uthread_mutex_t mutex2 = 0xCAFFE;

	assert (uthread_mutex_init(&mutex1) == MUTEX_SUCCESS);
	assert (uthread_mutex_init(&mutex1) == MUTEX_FAILURE);

	assert (uthread_mutex_lock(mutex2) == MUTEX_UNINITIALIZED);

	assert (uthread_mutex_lock(mutex1) == MUTEX_SUCCESS);
	assert (uthread_mutex_unlock(mutex1) == MUTEX_SUCCESS);

	assert (uthread_mutex_destroy(mutex1) == MUTEX_SUCCESS);
	assert (uthread_mutex_lock(mutex1) == MUTEX_UNINITIALIZED);
	assert (uthread_mutex_destroy(mutex1) == MUTEX_UNINITIALIZED);

	assert (uthread_mutex_init(&mutex2) == MUTEX_SUCCESS);
	assert (uthread_mutex_lock(mutex2) == MUTEX_SUCCESS);

}
